package com.sky.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sky.context.BaseContext;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.Employee;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Api(tags = "套餐相关接口")
@Slf4j
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 分页查询
     * @param dishPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO){
        log.info("菜品分页查询：{}", dishPageQueryDTO);
        PageResult pageResult = dishService.pageQuery(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 新增菜品
     */
    @PostMapping
    @ApiOperation("新增菜品")
    Result<String> save(DishVO dishVO){
        log.info("菜品新增：{}", dishVO);
        dishService.save(dishVO);
        return Result.success("新增菜品成功");
    }

    /**
     * 根据id查询单个菜品信息
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询单个菜品信息")
    Result<DishVO> GetById(@PathVariable Long id){
        DishVO dishVO = new DishVO();
        Dish dish = dishService.getById(id);
        BeanUtils.copyProperties(dish, dishVO);
        return Result.success(dishVO);
    }

    /**
     * 修改菜品
     */
    @PutMapping
    @ApiOperation("修改菜品")
    Result<String> update(DishVO dishVO){
        dishService.update(dishVO);
        return Result.success("修改成功");
    }

    /**
     * 批量删除菜品
     */
    @DeleteMapping
    @ApiOperation("批量删除菜品")
    Result<String> remove(long[] ids){
        dishService.remove(ids);
        return Result.success("删除成功");
    }

    /**
     * 菜品起售、停售
     */
    @PostMapping("/status/{status}")
    @ApiOperation("菜品起售、停售")
    Result<String> status(@PathVariable Long status, Long id){
        dishService.updateStatus(status, id);
        return Result.success("修改成功");
    }

    /**
     * 根据分类id查询菜品
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品")
    Result<List<DishVO>> list(Long categoryId){

        List<DishVO> list = dishService.list(categoryId);

        return Result.success(list);
    }
}
